JavaScript Replace all
replaceAll() returns a new string with every occurrence of the search value replaced. It is the natural fix for replace()’s "first match only" behaviour, without needing a global regex.
Syntax
str.replaceAll(search, replacement) Examples
| Input | Arguments | Output |
|---|---|---|
| "a-b-c" | "-", "+" | "a+b+c" |
Gotchas
- With a regex argument the /g flag is mandatory, or it throws.
Try it live
Type your input and see Replace all transform it instantly.
Want to go further? Chain Replace all with other functions in the visual Playground — pipe one output into the next and watch your data transform.